import React, { useState } from 'react'
import { Input, Button } from 'antd'
import store from './store';
import { addTodolist } from '../api/http';
//添加数组 == 修改redux管理的数据
export default function Add() {

  //获取输入的值的
  let [title, setTitle] = useState('')
  //console.log(title);

  return (
    <div>
      <Input value={title} onChange={(e) => {
        setTitle(e.target.value)
      }}

        suffix={<Button onClick={async () => {
          //修改reudx的状态
          let obj = {
            id: new Date().getTime(),
            title,
            sed: false
          }
          //使用中间件处理异步
          /*  let res = await addTodolist()
           store.dispatch({
             type:'get_list',
             payload:res
           }) */
          store.dispatch(async () => {
            let res = await addTodolist(obj)
            //组件修改状态:dispatch执行发送一个action对象，通知reducer修改状态
            store.dispatch({
              type: 'add_list',
              payload: res
            })
          })

        }}>添加</Button>} />
    </div>
  )
}
